package com.mvc.controller;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.ModelAndView;

@Controller  
public class FirstController {

	@Autowired  
	private  HttpServletRequest request;
	
	
	@Autowired
	private HttpSession session;
	
	
    @RequestMapping(value = "/login", method = RequestMethod.POST)  
    public ModelAndView myMethod(HttpServletRequest request,HttpServletResponse response,   
            ModelMap modelMap) throws Exception {  
        // @PathVariable("user") String user,
    	String user = request.getParameter("user");
    	WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();  
        ServletContext servletContext = webApplicationContext.getServletContext();  
        
        
    	modelMap.put("loginUser", user); 
        return new ModelAndView("hello", modelMap); 
    }  
	    
    @RequestMapping(value = "/welcome", method = RequestMethod.GET)  
    public String registPost(HttpServletRequest request,HttpServletResponse response) {  
    	System.out.println("2----------------"+request.getServletPath());
        return "welcome";  
    }  
    

}